<?php
include("../../model/config.php");

$term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends

$search1 = str_replace("?", "_", $term);
$search2 = str_replace("*", "%", $search1);

$qstring = "SELECT DISTINCT LastName FROM patient WHERE Id IN(Select PatientId from Screening) AND LastName LIKE '%{$search2}%' LIMIT 10";
$result = mysql_query($qstring);//query the database for entries containing the term

while ($row = mysql_fetch_array($result,MYSQL_ASSOC))//loop through the retrieved values
{
		$row['LastName']=htmlentities(stripslashes($row['LastName']));
		//$row['Id']=(int)$row['Id'];
		$row_set[] = $row['LastName'];//build an array
}
echo json_encode($row_set);//format the array into json data

?>
